package com.runssnail.demo.spring.web.action.member;

import com.runssnail.demo.spring.biz.dao.MemberDAO;
import com.runssnail.demo.spring.biz.domain.MemberDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.context.request.NativeWebRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by zhengwei on 2016/2/4.
 */
@Controller
@RequestMapping("member")
public class MemberAction {

    @Autowired
    private MemberDAO memberDAO;

    @RequestMapping("add")
    public String addMember(HttpSession session) {
        MemberDO member = new MemberDO();
        member.setId(2L);
        member.setFullName("bob");
        session.setAttribute("member", member);

        return "success";
    }

    @RequestMapping("get")
    public void getMember(HttpServletRequest request, NativeWebRequest nativeWebRequest, Model model) {
        HttpSession session = request.getSession();
        model.addAttribute("member", session.getAttribute("member"));
    }
}
